package fr.umlv.information;

import java.awt.BorderLayout;
import java.util.ResourceBundle;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;

import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;

import fr.umlv.authentication.SessionHandler;
import fr.umlv.metadata.MetadataModel;
import fr.umlv.metadata.MetadataTable;
import fr.umlv.properties.DataPropertiesTableModel;
import fr.umlv.versionning.DataVersionTableModel;
import fr.umlv.versionning.VersionningTable;

// TODO: Auto-generated Javadoc
/**
 * The Class PanelInformation.
 */
public class PanelInformation extends JPanel {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
	
	/** The bundle. */
	private ResourceBundle bundle = ResourceBundle.getBundle("kiyut.ekspos.BrowserWindow",SessionHandler.getLocale());
	
	/**
	 * Instantiates a new panel information.
	 *
	 * @param file the file
	 * @param index the index
	 */
	public PanelInformation(CmisObject file, int index) {

		setLayout(new BorderLayout());
		//setName("Zone Informations");
		JTabbedPane tabbedPane = new JTabbedPane();

		//creation du table contenant les properties
		DataPropertiesTableModel modelProp = new DataPropertiesTableModel(file.getProperties().size(), 2, file.getProperties());
		JScrollPane scrollProp = new JScrollPane(new JTable(modelProp));
		scrollProp.setName(bundle.getString("tabbedProperties.text"));
		tabbedPane.add(scrollProp);
		
		//creation du table contenant les versions pour un fichier
		if(!(BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId()))){
			//creation du table contenant les metadata
			MetadataModel modelMeta = new MetadataModel(file.getProperties());
			JScrollPane scrollMeta = new MetadataTable(modelMeta,bundle.getString("tabbedMetadata.text"));
			tabbedPane.add(scrollMeta);
			
			final Document doc = (Document)file;	
			//construction du tableau contenant les versions
			DataVersionTableModel modelVersion = new DataVersionTableModel(doc);
			JScrollPane scrollVersion = new VersionningTable(modelVersion,doc);
			tabbedPane.add(scrollVersion);
		}
		
		tabbedPane.setSelectedIndex(index);
		add(tabbedPane, BorderLayout.CENTER);
		//setSize(500,300);
		
	}
}
